package com.bootdo.testDemo

import org.beetl.core.Configuration
import org.beetl.core.GroupTemplate
import org.beetl.core.resource.ClasspathResourceLoader
import org.junit.Test
import java.io.File
import java.io.FileOutputStream

class BeetlBasicTest {

  @Test
  fun generate() {
    val params:MutableMap<String, Any> = mutableMapOf()
    params["className"] = "Test"
    params["classname"] = "test"
    params["moduleName"] = "system"
    params["pathName"] = "test"
    params["comment"] = "测试管理"
    params["tableName"] = "ext_test"

    val resourceLoader = ClasspathResourceLoader("templates/common/generator/beetl/")
    val cfg = Configuration.defaultConfiguration()
    val gt = GroupTemplate(resourceLoader, cfg)
    renderTo(gt, params, "group", "Group.kt")
    renderTo(gt, params, "group-dao", "Dao.kt")
    renderTo(gt, params, "group-mapper", "Mapper.xml")
  }

  fun renderTo(gt:GroupTemplate, params:MutableMap<String, Any>, tplName:String, fileName:String) {
    val targetPath="D:/tmp/tpl"
    val t = gt.getTemplate("${tplName}.btl")
    t.binding(params)
    t.renderTo(FileOutputStream(File("${targetPath}/${params["className"]}${fileName}")))
  }

  @Test
  fun g111() {
    val testInit = MyTestInit()
    print(testInit.index())
  }

}

open class TestInit {
  var prefix:String = "hel"
  constructor() {
    println("forked")
    prefix = "check"
  }
  fun index():String = "${prefix}, shit!"
}

class MyTestInit: TestInit()

